﻿using System;
using System.Collections.Generic;
using System.Linq;
using iSun.Common;
using iSun.BLL.Base;
using iSun.Model;
using iSun.Entity;

namespace iSun.BLL.Base
{
    public   class LogBusiness
    {
        /// <summary>
        /// 写日志
        /// </summary>
        /// <param name="x"></param>
        public static void WriteExceptionLog(Exception x, DatUser user)
        {
            SysError error = new SysError();

            error.Message = x.Message;
            error.StackTrace = x.StackTrace;
            error.Source = x.Source;
            error.Method = x.TargetSite.Name;
            BaseBussnies buss = new BaseBussnies();
            iSun.Model.SysDataLog log = new SysDataLog();
            log.UserID = user.UserID;
            log.Action = "ExceptionLog";
            log.Data = error.ToJSON();
            log.EntityName = "SysError";
            log.LogTime = DateTime.Now;
            buss.entity = log;
            buss.Insert();
        }

        public static void WriteRecordLog(string entity,string Json, DatUser user)
        {
            BaseBussnies buss = new BaseBussnies();
            iSun.Model.SysDataLog log = new SysDataLog();

            log.UserID = user.UserID;
            log.Action = "RecordLog";
            log.Data = Json;
            log.EntityName =entity;
            log.LogTime = DateTime.Now;
            buss.entity = log;
            buss.Insert();
        }


        public static void WriteRecordLog(BaseEntity entity,DatUser user)
        {
            BaseBussnies buss = new BaseBussnies();
            iSun.Model.SysDataLog log = new SysDataLog();
            log.UserID = user.UserID;
            log.Action = "RecordLog";
            log.Data = entity.ToJSON();
            log.EntityName = entity.GetTableName();
            log.LogTime = DateTime.Now;
            buss.entity = log;
            buss.Insert();
        }


        public static void WriteRecordLog(DataTableBaseEntity entity, DatUser user)
        {
            BaseBussnies buss = new BaseBussnies();
            iSun.Model.SysDataLog log = new SysDataLog();

            log.UserID = user.UserID;
            log.Action = "RecordLog";
            log.Data = entity.EntityJson;
            log.EntityName = entity.GetTableName();
            log.LogTime = DateTime.Now;
            buss.entity = log;
            buss.Insert();
        }


    }
}
